package com.susallwave.srcb.controller.sys.others;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.susallwave.srcb.aspect.MyLog;
import com.susallwave.srcb.entity.sys.OperationLog;
import com.susallwave.srcb.response.Result;
import com.susallwave.srcb.service.sys.OperationLogService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统操作日志 前端控制器
 * </p>
 *
 * @author MyBatisPlusGenerator
 * @since 2025-07-22
 */
@RestController
@RequestMapping("/log")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "日志管理", description = "日志查询等操作")
public class OperationLogController {
    private final OperationLogService logService;

    @MyLog(enabled = false)
    @PostMapping("/list")
    public Result<IPage<OperationLog>> listLogs(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam(required=false) String startTime,
            @RequestParam(required = false) String endTime,
            @RequestBody OperationLog vo) {
        return logService.listLogs(pageNum,pageSize,startTime,endTime,vo);
    }

    @GetMapping("/single")
    public Result<OperationLog> single(@RequestParam Long id) {
        return Result.success(logService.getById(id));
    }

    @DeleteMapping("/deleteBatch")
    public Result<Void> deleteBatch(@RequestBody List<Long> ids) {
        logService.removeByIds(ids);
        return Result.success();
    }
}
